package com.sunspring.zdcall.config;

import com.sunspring.zdcall.aop.LoginInterceptor;
import com.sunspring.zdcall.util.FileUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 控制层全局配置
 * @Author WuLei
 * @Date 2018/11/27  14:41
 */
@Component
public class GlobalWebConfig implements WebMvcConfigurer {

    @Autowired
    private LoginInterceptor loginInterceptor;

    @Override
    public void addCorsMappings(CorsRegistry registry) {
        //允许跨域
       registry.addMapping("/**");
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(loginInterceptor)
                .addPathPatterns("/sys/**")
                .excludePathPatterns("/sys/adminLogin");
    }

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler(FileUtil.PATTERNS + "*").addResourceLocations("file:///" + FileUtil.RESOURCES_LOCATION);
    }
}
